home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Chat & Communication / Digsby build 37 / digsby_setup.exe / lib / compiler / future.pyo (.txt) < prev    next >
Python Compiled Bytecode  |  2008-10-13  |  3KB  |  83 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  3.  
  4. from compiler import ast, walk
  5.  
  6. def is_future(stmt):
  7.     if not isinstance(stmt, ast.From):
  8.         return 0
  9.     
  10.     if stmt.modname == '__future__':
  11.         return 1
  12.     else:
  13.         return 0
  14.  
  15.  
  16. class FutureParser:
  17.     features = ('nested_scopes', 'generators', 'division', 'absolute_import', 'with_statement')
  18.     
  19.     def __init__(self):
  20.         self.found = { }
  21.  
  22.     
  23.     def visitModule(self, node):
  24.         stmt = node.node
  25.         for s in stmt.nodes:
  26.             if not self.check_stmt(s):
  27.                 break
  28.                 continue
  29.         
  30.  
  31.     
  32.     def check_stmt(self, stmt):
  33.         if is_future(stmt):
  34.             for name, asname in stmt.names:
  35.                 if name in self.features:
  36.                     self.found[name] = 1
  37.                     continue
  38.                 raise SyntaxError, 'future feature %s is not defined' % name
  39.             
  40.             stmt.valid_future = 1
  41.             return 1
  42.         
  43.         return 0
  44.  
  45.     
  46.     def get_features(self):
  47.         return self.found.keys()
  48.  
  49.  
  50.  
  51. class BadFutureParser:
  52.     
  53.     def visitFrom(self, node):
  54.         if hasattr(node, 'valid_future'):
  55.             return None
  56.         
  57.         if node.modname != '__future__':
  58.             return None
  59.         
  60.         raise SyntaxError, 'invalid future statement ' + repr(node)
  61.  
  62.  
  63.  
  64. def find_futures(node):
  65.     p1 = FutureParser()
  66.     p2 = BadFutureParser()
  67.     walk(node, p1)
  68.     walk(node, p2)
  69.     return p1.get_features()
  70.  
  71. if __name__ == '__main__':
  72.     import sys
  73.     from compiler import parseFile, walk
  74.     for file in sys.argv[1:]:
  75.         print file
  76.         tree = parseFile(file)
  77.         v = FutureParser()
  78.         walk(tree, v)
  79.         print v.found
  80.         print 
  81.     
  82.  
  83.